
import { getMvAll } from '../../api/services/api'
export default ({
    namespaced: true,
    state: {
        currentType: {
            area: '全部',
            type: '全部',
            order: '上升最快',
            limit: 24,
            currentPage: 1
        },
        mvsList: [],
        loading: false,
    },
    mutations: {
        changeMvsList(state, val) {
            state.mvsList = [...state.mvsList, ...val];
        },
        changeLoading(state, val) {
            state.loading = !state.loading;
        },
        //改变MV类型
        changeCurrentType(state, val) {
            state.currentType.currentPage = 1;
            state.mvsList = [];
            state.currentType.type = val;
        },
        //改变地区类型
        changeCurrentArea(state, val) {
            //每次触发滚动事件currentPage都会增加，导致切换类型时，加载的数据就不是第一页的，所以得重置
            state.currentType.currentPage = 1;
            state.mvsList = [];
            state.currentType.area = val;
        },
        //改变排序
        changeOrder(state, val) {
            state.currentType.currentPage = 1;
            state.mvsList = [];
            state.currentType.order = val;
        },
        changeCurrentPage(state, val) {
            state.currentType.currentPage++;
        }

    },
    actions: {
        async getMvAll(context, val) {
            context.commit('changeLoading');
            const { area, type, order, limit, currentPage } = context.state.currentType;
            const data = await getMvAll(area, type, order, limit, currentPage);
            console.log(data);
            if (data.code == 200) {
                context.commit('changeLoading');
                context.commit('changeMvsList', data.data);
            }
        }


    },

})
